﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services;

namespace Catering.Catering_Page.Caipin.Caipin_jcsz
{
    public partial class Caipushezhi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Ajax.Utility.RegisterTypeForAjax(typeof(Caipushezhi));
            if (!IsPostBack)
            {
                this.LoadDrop();
                this.LoadRep();
            }
        }

        //加载下拉菜单
        public void LoadDrop()
        {
            DataTable dt_tedian = new Catering_Rules.Group_tedian().GetAllList().Tables[0];
            this.drop_tedian.LoadDrop(dt_tedian, "id", "PName");
        }

        //加载数据列表
        public void LoadRep()
        {
            DataTable dt_library = new Catering_Rules.library().GetAllList().Tables[0];
            this.Rep_shipu.DataSource = dt_library;
            this.Rep_shipu.DataBind();
        }

        //获取食谱库信息
        [Ajax.AjaxMethod]
        public DataTable GetlibraryByID(string strid)
        {
            return new Catering_Rules.library().GetList("id="+strid).Tables[0];
        }

        //修改食谱库
        [WebMethod]
        public static string Edit_library(string CID, string LName, string Back, string temp1)
        {
            Catering_Model.library md = new Catering_Model.library();
            md.id = Convert.ToInt32(CID);
            md.LName = LName;
            md.Back = Back;
            md.temp1 = temp1;
            return new Catering_Rules.library().Update(md) ? "OK" : "NO";
        }

        //添加食谱库
        [WebMethod]
        public static string Add_library(string LName, string Back, string temp1)
        {
            Catering_Model.library md = new Catering_Model.library();
            md.LName = LName;
            md.Back = Back;
            md.temp1 = temp1;
            new Catering_Rules.library().Add(md);
            return "OK";
        }

        //删除食谱库
        [WebMethod]
        public static string Del_library(string strid)
        {
            return new Catering_Rules.library().Delete(Convert.ToInt32(strid)) ? "OK" : "NO";
        }

        //获取菜谱库对应的人群特点
        public string Get_Group_tedianName(string strid)
        {
            return new Catering_Rules.Group_tedian().GetModel(Convert.ToInt32(strid)).PName;
        }
    }
}